package gb.ord;

import gb.struct.Monomial;

import java.util.Comparator;


public class GradedOrd implements Comparator<Monomial> {

    public int compare(Monomial m1, Monomial m2) {
        if (m1 != null) {
            if (m2 != null) {
                int r = m2.sumOfPowers() - m1.sumOfPowers();
                if (r == 0) {
                    return m2.getPower(0) - m1.getPower(0);
                } else {
                    return r;
                }
            } else {
                return -1 * m1.sumOfPowers();
            }
        } else if (m2 != null){
            return m2.sumOfPowers();
        } else {
            return 0;
        }
    }
}
